package stack_test;

import java.util.Stack;

public class test {
}

class Solution {
    public boolean validPalindrome(String s) {
        //不删除直接判断
        if (orVaild(s)) {
            return true;
        }
        int index = 0;
        String s1 = "";
        //删除一个，再次判断
        for (int j = 0; j < s.length(); j++){
            for (int i = 0; i < s.length(); i++) {
                if (index != i) {
                    s1 = s1 + s.charAt(i);
                }
            }
            index++;
            if(orVaild(s1)){
                return true;
            }
        }
        return false;
    }

    //判断是否是回文串的方法
    public boolean orVaild(String s) {
        char[] arr = s.toCharArray();
        //使用栈实现回文串的判断
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < arr.length; i++) {
            stack.add(arr[i]);
        }

        //出栈
        String otherString = "";
        while (!stack.isEmpty()) {
            otherString = otherString + stack.peek();
            stack.pop();
        }
        if (otherString.equals(s)) {
            return true;
        }
        return false;
    }
}
